import axios from "axios";

export const requestCodeByIp = () =>
  axios
    .get("https://restapi.amap.com/v3/ip", {
      params: {
        key: "e0a4679c586576d60f508ab52660b22c",
      },
    })
    .then((res) => {
      return res.data;
    })
    .catch((error) => {
      console.log(error);
    });

export const requestWeatherByCode = (adcode) =>
  axios
    .get("https://restapi.amap.com/v3/weather/weatherInfo", {
      params: {
        city: adcode,
        key: "e0a4679c586576d60f508ab52660b22c",
        extensions: "all",
      },
    })
    .then((res) => {
      return res.data;
    })
    .catch((error) => {
      console.log(error);
    });

export const requestWeatherByName = (cityName) =>
  axios
    .get("https://restapi.amap.com/v3/geocode/geo?", {
      params: {
        address: cityName,
        key: "e0a4679c586576d60f508ab52660b22c",
      },
    })
    .then((res) => {
      return res.data;
    })
    .catch((error) => {
      console.log(error);
    });
export const requestWeatherLiveByCode = (adcode) =>
  axios
    .get("https://restapi.amap.com/v3/weather/weatherInfo", {
      params: {
        city: adcode,
        key: "e0a4679c586576d60f508ab52660b22c",
        extensions: "base",
      },
    })
    .then((res) => {
      return res.data;
    })
    .catch((error) => {
      console.log(error);
    });
